package com.chen.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MyMessageListener {
    //交换机
    public static final String EXCHANGE_DIRECT = "exchange1";
    //路由键
    public static final String ROUTING_KEY = "routingKey1";
    //队列名称
    public static final String QUEUE_NAME = "queue1";

// 写法一可以创建路由队列和他们之间的绑定关系并监听
//    @RabbitListener(
//            bindings = @QueueBinding(value = @Queue(value = QUEUE_NAME, durable = "true"),
////                    exchange = @Exchange(value = EXCHANGE_DIRECT),
//                     exchange = @Exchange(EXCHANGE_DIRECT), //就一个value属性可以省略value=xx
//                    key = {ROUTING_KEY}
//            )
//    )

    //写法二不需要创建, 只需要指定要监听的队列即可. 提起是已经都建立好
    @RabbitListener(queues = {QUEUE_NAME})
    public void proceedMessage(String data, Message message, Channel channel) {
        System.out.println("消费端接收到了消息:"+data);
    }
}
